﻿@using MvcApplicationTest.Controllers
@{
    ViewBag.Title = "Your today's order";
}


<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title></title>
</head>
<body>
    <div>
        <h2>@ViewBag.Title.</h2>
        <div>
            <li>Today's orders:
                @Utility.DisPlayOrderInfos(ViewBag.UserOrderInfos)
                Your blance: @ViewBag.UserBalance
            </li>
            <input type="button" value="Delete Orders" onclick="DeleteOrders_OnClick()" />
        </div>
    </div>
    <aside>
        <h3>Return:</h3>
        <ul>
            <li>@Html.ActionLink("Order Now", "OrderPage", "Home")</li>
            <li>@Html.ActionLink("Today's Order", "OrderResult", "Home")</li>
            <li>@Html.ActionLink("Order History", "OrderHistory", "Home")</li>
            <li>@Html.ActionLink("Change Your Information", "Register", "Account", new { id = "CYI" }, null)</li>
        </ul>
    </aside>
</body>

<script type="text/javascript">
    function DeleteOrders_OnClick() {
        var $orders = $("input[name=DisPlayedOrder]");
        var obj = [];
        for (var i = 0; i < $orders.length; i++) {
            if ($orders[i].checked) {
                $selectedItem = $($orders[i]);
                obj.push($selectedItem.attr("userorder") + "|" + $selectedItem.attr("cost") + "|" + $selectedItem.attr("ordertime"));
            }
        }
        var str = obj.toString();
        $.ajax({
            type: "POST",
            url: "/Home/DeleteOrders",
            datatype: "json",
            data: { "str": str },
            async: false,
            success: function (result) {
                if ("UserAttackSystemError" == result) {
                    alert("Warning, we have record your name, if you try to attack the system second time, your user would be killed.")
                }
                else {
                    window.location.href = "../../Home/OrderResult";
                }
            },
            error: function (error) {
            }
        });
        //使用刷新页面，需要给balance,checkbox赋值，不使用动态删除
    }
</script>
</html>

